import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/widgets/app/app_task_list_item.dart';
import 'package:bxultimate/widgets/mk_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

import 'controller.dart';
import 'widget/item.dart';

class TaskListPage extends StatefulWidget {
  const TaskListPage({Key? key}) : super(key: key);

  @override
  State<TaskListPage> createState() => _TaskListPageState();
}

class _TaskListPageState extends State<TaskListPage> {
  final controller = Get.find<TaskListController>();
  final state = Get.find<TaskListController>().state;

  @override
  Widget build(BuildContext context) {
    return MkPage(
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: AppBar(
          backgroundColor: Colors.transparent,
          title: Text('我的任务'),
          bottom: PreferredSize(
            preferredSize: Size.fromHeight(40),
            child: TDTabBar(
              tabs: state.tabs.map((e) => TDTab(text: e.label)).toList(),
              controller: controller.tabController,
              showIndicator: true,
              backgroundColor: Colors.transparent,
              isScrollable: false,
            ),
          ),
        ),
        body: TabBarView(
          children: [
            for (var i = 0; i < state.tabs.length; i++)
              _buildList(state.tabs[i].value)
          ],
          controller: controller.tabController,
        ),
      ),
    );
  }

  _buildList(String? status) {
    return TabItemView(status:status!);
  }

  @override
  void dispose() {
    Get.delete<TaskListController>();
    super.dispose();
  }
}
